﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace carsitem.StockManagement
{
    public partial class StockManagementPlanForm : Form
    {
        
        //皮肤组件声明
        Sunisoft.IrisSkin.SkinEngine se = null;
        string SkinName = "SteelBlack";

        public StockManagementPlanForm()
        {
            InitializeComponent();

            //皮肤组件引用
            se = new Sunisoft.IrisSkin.SkinEngine();
            se.SkinAllForm = true;
            se.SkinFile = "skin/" + SkinName + ".ssk";
        }

        //退出按钮
        private void Exit_Click(object sender, EventArgs e)
        {
            carsitem.MainInterface.MainInterfaceForm mainInterfaceForm = new carsitem.MainInterface.MainInterfaceForm();//把form1传给form2
            mainInterfaceForm.Show();
            this.Hide();//把自己隐藏了
        }

        //打开窗口更新表格
        private void StockManagementPlanForm_Load(object sender, EventArgs e)
        {
            LoadCangKu();
            string sql = string.Format("select * from StockManagement");
            DataTable dt = DBHelper.Instance().GetDataTableBySql(sql);
            this.dataGridView1.AutoGenerateColumns = false;
            this.dataGridView1.DataSource = dt;
        }

        //删除按钮
        private void Delete_Click(object sender, EventArgs e)
        {
            //连接删除窗口，并打开
            DBHelper db = new DBHelper();
            StockManagementPlanDeleteForm stockManagementPlanDeleteForm = new StockManagementPlanDeleteForm();
            stockManagementPlanDeleteForm.OrderNumber = Convert.ToInt32(this.dataGridView1.SelectedRows[0].Cells[0].Value);
            stockManagementPlanDeleteForm.Owner = this;
            stockManagementPlanDeleteForm.Show();

            this.Hide();//把自己隐藏了
        }

        //sql重连方法
        public void LoadCangKu()
        {
            string sql1 = string.Format("select * from StockManagement");
            DataTable dt = DBHelper.Instance().GetDataTableBySql(sql1);
            this.dataGridView1.AutoGenerateColumns = false;
            this.dataGridView1.DataSource = dt;
        }

        //修改按钮
        private void Modify_Click(object sender, EventArgs e)
        {
            //连接修改窗口，并打开
            DBHelper db = new DBHelper();
            StockManagementPlanModifyForm stockManagementPlanModifyForm = new StockManagementPlanModifyForm();
            stockManagementPlanModifyForm.OrderNumber = Convert.ToInt32(this.dataGridView1.SelectedRows[0].Cells[0].Value);
            stockManagementPlanModifyForm.Owner = this;
            stockManagementPlanModifyForm.Show();

            this.Hide();//隐藏自己
        }
    }
}
